package org.millioncall.yueyoga.common.weixin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
	private static Logger log = LoggerFactory.getLogger(Main.class);

	//	private void createMenu(){
	public static void main(String[] args) {
		// 第三方用户唯一凭证
		String appId = "wx66ef428c9ab421e2";
		// 第三方用户唯一凭证密钥
		String appSecret = "8bd2b3c70590728a8941e5f278139e30";

		// 调用接口获取access_token
		AccessToken at = WeixinUtil.getAccessToken(appId, appSecret);
		if (null != at) {
			// 调用接口创建菜单
			int result = WeixinUtil.createMenu(getMenu(), at.getToken());
			// 判断菜单创建结果
			if (0 == result){
				System.out.println("OK");
				log.info("菜单创建成功！");
			}
			else{
				System.out.println("NO");
				log.info("菜单创建失败，错误码：" + result);
			}
		}
	}
	/** 
     * 组装菜单数据 
     *  
     * @return 
     */  
    private static Menu getMenu() {
    	 Weixin_Button btn1 = new Weixin_Button();
         btn1.setName("预约订座");
         btn1.setType("click");
         btn1.setKey("dingzuo");

         Weixin_Button btn2 = new Weixin_Button();
         btn2.setName("会员绑定");

         Weixin_Button btn22=new Weixin_Button();
         btn22.setName("使用卡号");
         btn22.setType("click");
         btn22.setKey("outidbangding");
         
         Weixin_Button btn23=new Weixin_Button();
         btn23.setName("使用手机号");
         btn23.setType("click");
         btn23.setKey("mobilebangding");
         
         btn2.setSub_button(new Weixin_Button[]{btn22,btn23});
         
         
         Weixin_Button btn3 = new Weixin_Button();
         btn3.setName("其它功能");
         
         Weixin_Button btn31=new Weixin_Button();
         btn31.setName("一键咨询");
         btn31.setType("view");
         btn31.setUrl("http://center.qdyoga.com/app/admin/app/phone.html#mp.weixin.qq.com");
         
         Weixin_Button btn32=new Weixin_Button();
         btn32.setName("解除绑定");
         btn32.setType("click");
         btn32.setKey("clearbangding");
         
         Weixin_Button btn33=new Weixin_Button();
         btn33.setName("取消全部预约");
         btn33.setType("click");
         btn33.setKey("quxiaodingzuo");
         
         btn3.setSub_button(new Weixin_Button[]{btn31,btn32,btn33});
         
         Menu menu = new Menu();  
         menu.setButton(new Weixin_Button[] {btn1,btn2,btn3});  
   
         return menu;  
    }  
}